package com.design.pattern.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class RoomProxy<T>  implements InvocationHandler{
    private T obj;

    public RoomProxy(T obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if (!"sale".equals(method.getName())){
            return method.invoke(obj,args);
        }
        if (600 > (Integer) args[0]){
            System.out.println("价格太低,不联系房东");
            return null;
        }
        System.out.println("价格合适");
        return method.invoke(obj,args);
    }
}
